import os
import sys
import random
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class TaskList(QListWidget):
    info_Signal=pyqtSignal(dict)
    def __init__(self,data_list):
        super(TaskList, self).__init__()

        self.data_list=data_list
        self.init_data(data_list)
        self.clicked.connect(self._show_info)

    def init_data(self,data_list):
        #{'description': '后山环境，气浪逐渐靠近人员', 'entity_name': 'HYX01_43_036', 'eps': '01_43',
        # 'img_path': '/upload/image/proj_by/min/ca29e095a578cc5347c817fa40c225cb.png', 'frame': '35',
        # 'fps': '25', 'shot_difficulty_level': ''}
        if data_list:
            for i in data_list:
                text=i['entity_name']
                item=QListWidgetItem()
                item.setText(text)
                item.setSizeHint(QSize(100, 35))
                item.setTextAlignment(Qt.AlignCenter)
                # item.setBackground(QBrush(QColor(random.randint(0,256),random.randint(0,256),random.randint(0,256))))
                item.setBackground(QBrush(QColor('#FFDEAD')))
                item.setData(5,i)
                self.addItem(item)
            self.sortItems()

    def _show_info(self,index):
        print('_show_info:',index)
        item=self.itemFromIndex(index)
        data=item.data(5)
        print(data)
        self.info_Signal.emit(data)


class TaskInfoWindow(QWidget):#显示任务信息
    def __init__(self,data_list):
        super(TaskInfoWindow, self).__init__()

        self.big_font=QFont('',20,65)
        self.setWindowTitle('镜头列表')
        self.main_layout=QHBoxLayout()
        self.left_list=TaskList(data_list)
        self.left_list.info_Signal.connect(self.show_info)
        self.right_layout=QVBoxLayout()
        self.right_layout.setAlignment(Qt.AlignTop)
        self.right_label_layout=QHBoxLayout()
        self.right_label_layout.setAlignment(Qt.AlignCenter)
        self.right_label=QLabel('镜头信息')
        self.right_label.setFont(self.big_font)
        self.right_label_layout.addWidget(self.right_label)
        self.right_text_brow=QTextBrowser()
        self.right_layout.addLayout(self.right_label_layout)
        self.right_layout.addWidget(self.right_text_brow)
        self.main_layout.addWidget(self.left_list)
        self.main_layout.addLayout(self.right_layout)
        self.setLayout(self.main_layout)

    def show_info(self,data):
        self.right_text_brow.clear()
        text='镜头号:{}\n\n集数:{}\n\n帧数:{}\n\n难度等级:{}\n\n内容描述:{}'.format(data['entity_name'],data['eps'],data['frame'],data['shot_difficulty_level'],data['description'])
        self.right_text_brow.setText(text)

if __name__ == '__main__':
    app=QApplication(sys.argv)
    shot_data_list=[{'description': '后山环境，气浪逐渐靠近人员', 'entity_name': 'HYX01_43_036', 'eps': '01_43', 'img_path': '/upload/image/proj_by/min/ca29e095a578cc5347c817fa40c225cb.png', 'frame': '35', 'fps': '25', 'shot_difficulty_level': ''},
                     {'description': '修灯穿帮（看图片备注字段）', 'entity_name': 'PH30_011_001', 'eps': '30sPH', 'img_path': '/upload/image/proj_by/min/aecf02bb63a56cea8c2a2b521363314b.png', 'frame': '33', 'fps': '25', 'shot_difficulty_level': 'D'},
                     {'description': '后山环境，怀沙加流光，擦头套', 'entity_name': 'PH30_003', 'eps': '30sPH', 'img_path': '/upload/image/proj_by/min/3faeffc337be9c59c4b0aff88a6a684d.png', 'frame': '23', 'fps': '25', 'shot_difficulty_level': 'B'},
                     {'description': '擦头套', 'entity_name': 'PH1min_005', 'eps': '30sPH', 'img_path': '/upload/image/proj_by/min/d30e368e3ee3eb93f55dbc0ed14bc991.png', 'frame': '30', 'fps': '25', 'shot_difficulty_level': ''},
                     {'description': '楚晚宁法术抵抗', 'entity_name': 'PH1min_009', 'eps': '30sPH', 'img_path': '/upload/image/proj_by/min/95147674f0b55501af4e7b80ae223788.png', 'frame': '48', 'fps': '25', 'shot_difficulty_level': 'C'},
                     {'description': '红莲水榭夜景，放烟花，有飘雪（看图片备注里面的概念）', 'entity_name': 'PH1min_001', 'eps': '30sPH', 'img_path': '/upload/image/proj_by/min/f19a3ad695a67919487de31e1d318121.png', 'frame': '131', 'fps': '25', 'shot_difficulty_level': 'B'},
                     {'description': '换天，屋顶做延伸，擦维亚，两人对阵身上加自身法术元素', 'entity_name': 'PH1min_022', 'eps': '30sPH', 'img_path': '/upload/image/proj_by/min/e46e233b7529d5745b9c85cb3837a618.png', 'frame': '521', 'fps': '25', 'shot_difficulty_level': 'C'},
                     {'description': '日景红莲水榭环境，延伸的环境山体加瀑布，花瓣飘，树冠补密一点', 'entity_name': 'PH1min_018', 'eps': '30sPH', 'img_path': '/upload/image/proj_by/min/1f281cc3c031c4f7977396b8fa72d01c.png', 'frame': '37', 'fps': '25', 'shot_difficulty_level': 'B'},
                     {'description': '日景丹心殿外（墨燃拜师，气氛可以美一点）', 'entity_name': 'PH1min_010', 'eps': '30sPH', 'img_path': '/upload/image/proj_by/min/cee5d809a941e2747aaa2e3d0fc2f1f0.png', 'frame': '28', 'fps': '25', 'shot_difficulty_level': 'C'},
                     {'description': '夜景丹心殿外，远处有烟花', 'entity_name': 'PH1min_006', 'eps': '30sPH', 'img_path': '/upload/image/proj_by/min/0592232920565b9398f4de16058a4ac2.png', 'frame': '36', 'fps': '25', 'shot_difficulty_level': 'D'}]
    t=TaskInfoWindow(shot_data_list)
    t.show()
    sys.exit(app.exec_())

